package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.service.SettingDetailsService;
import com.wuseguang.springcloud.util.CodeUtil;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @描述 班牌设置页面详情
 * @创建人 zm
 * @创建时间 2020/2/14
 */
@RestController
@RequestMapping("/brands")
public class SettingDetailsController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SettingDetailsService detailsService;

    /**
     * @描述 查询设备类型
     * @创建人 zm
     * @创建时间 2020/2/23
     */
    @RequestMapping("/queryEquipmentType")
    public Result queryEquipmentType(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return new Result(detailsService.queryEquipmentType(deviceid));
    }

    /**
     * @描述 修改设备类型
     * @创建人 zm
     * @创建时间 2020/2/23
     */
    @RequestMapping("/updateEquipmentType")
    public Result updateEquipmentType(@RequestParam(value = "deviceid") String deviceid,
                                      @RequestParam(value = "deviceType") String deviceType) {
        logger.info("deviceid={}", deviceid);
        int i = detailsService.updateEquipmentType(deviceid, deviceType);
        if (i > 0) {
            return new Result();
        }
        return new Result(CodeUtil.MODIFICATION_FAILED);
    }


    /**
     * @描述 修改版本号
     * @创建人 zm
     * @创建时间 2020/4/6
     */
    @RequestMapping("/updateVersionNumber")
    public Result updateVersionNumber(@RequestParam(value = "deviceid") String deviceid,
                                      @RequestParam(value = "version") String version) {
        logger.info("deviceid={}", deviceid);
        int i = detailsService.updateVersionNumber(deviceid, version);
        if (i > 0) {
            return new Result();
        }
        return new Result(CodeUtil.MODIFICATION_FAILED);
    }

    /**
     * @描述 添加截图
     * @创建人 zm
     * @创建时间 2020/2/27
     */
    @RequestMapping("/updateScreenShot")
    public Result updateScreenShot(@RequestParam(value = "deviceid") String deviceid,
                                   @RequestParam(value = "screenShotUrl") String screenShotUrl) {
        logger.info("deviceid={}", deviceid);
        int i = detailsService.updateScreenShot(deviceid, screenShotUrl);
        if (i > 0) {
            return new Result();
        }
        return new Result(CodeUtil.MODIFICATION_FAILED);
    }

    /**
     * @描述 查询设备音量
     * @创建人 zm
     * @创建时间 2020/2/27
     */
    @RequestMapping("/queryVolume")
    public Result queryVolume(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return new Result(detailsService.queryVolume(deviceid));
    }

    /**
     * @描述 查询升级安装包url
     * @创建人 zm
     * @创建时间 2020/2/27
     */
    @RequestMapping("/queryUpGradeUrl")
    public Result queryUpGradeUrl(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return new Result(detailsService.queryUpGradeUrl(deviceid));
    }

    /**
     * @描述 查询推送日志
     * @创建人 zm
     * @创建时间 2020/5/5
     */
    @RequestMapping("/queryPushLog")
    public Result queryPushLog(@RequestParam(value = "deviceid", required = false) String deviceid) {
        logger.info("deviceid={}", deviceid);
        return detailsService.queryPushLog(deviceid);
    }

    /**
     * @描述 查询班牌日志
     * @创建人 zm
     * @创建时间 2020/6/12
     */
    @RequestMapping("/queryBancardLog")
    public Result queryBancardLog(@RequestParam(value = "deviceid") String deviceid,
                                  @RequestParam(value = "time") String time,
                                  @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                  @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        logger.info("deviceid={}", deviceid);
        return detailsService.queryBancardLog(deviceid, time, indexNo, rows);
    }

    /**
     * @描述 修改班牌日志
     * @创建人 zm
     * @创建时间 2020/6/13
     */
    @RequestMapping("/updateBancardLog")
    public Result queryBancardLog(@RequestParam(value = "deviceid") String deviceid,
                                  @RequestParam(value = "type") Integer type) {
        logger.info("deviceid={}", deviceid);
        return detailsService.updateBancardLog(deviceid, type);
    }


    @RequestMapping("/queryStudentInformation")
    public Result queryStudentInformation(@RequestParam(value = "phone", required = false) String phone,
                                          @RequestParam(value = "card", required = false) String card,
                                          @RequestParam(value = "name", required = false) String name) {
        return detailsService.queryStudentInformation(phone, card,name);
    }

    /**
     * @描述 查询班牌心跳日志状态
     * @创建人 zm
     * @创建时间 2020/6/13
     */
    @RequestMapping("/queryLogState")
    public Result queryLogState(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return detailsService.queryLogState(deviceid);
    }


    /**
     * @描述 根据设备号查所有心跳字段
     * @创建人 zm
     * @创建时间 2020/3/15
     */
    @RequestMapping("/queryHeartBydeviceId")
    public Result queryHeartBydeviceId(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return new Result(detailsService.queryHeartBydeviceId(deviceid));
    }

    /**
     * @描述 校验班牌密码
     * @创建人 zm
     * @创建时间 2020/4/3
     */
    @RequestMapping("/landingOfClassCards")
    public Result landingOfClassCards(@RequestParam(value = "deviceid") String deviceid, @RequestParam(value = "password", required = false) String password) {//學生id
        return detailsService.landingOfClassCards(deviceid, password);
    }

    /**
     * @描述 上传接口
     * @创建人 zm
     * @创建时间 2020/4/6
     */
    @PostMapping("/brandUpload")
    public Result brandUpload(@RequestPart("file") MultipartFile file, @RequestParam("type") int type, @RequestParam(value = "deviceid") String deviceid) {
        logger.info("班牌上传文件/图片/人脸");
        return detailsService.upload(deviceid, file, type);
    }

    @RequestMapping("/queryManageClassList")
    public Result queryManageClassList(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return detailsService.queryManageClassList(deviceid);
    }

    /**
     * @描述 发送下载班牌日志
     * @创建人 zm
     * @创建时间 2020/6/8
     */
    @RequestMapping("/updateBanCardUploadLog")
    public Result updateBanCardUploadLog(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return detailsService.updateBanCardUploadLog(deviceid);
    }

    /**
     * @描述 添加班牌日志
     * @创建人 zm
     * @创建时间 2020/6/8
     */
    @RequestMapping("/addBanCardUploadLog")
    public Result addBanCardUploadLog(@RequestParam(value = "deviceid") String deviceid, @RequestParam(value = "url") String url) {
        logger.info("deviceid={}", deviceid);
        return detailsService.addBanCardUploadLog(deviceid, url);
    }

    /**
     * @描述 查询班牌日志信息
     * @创建人 zm
     * @创建时间 2020/6/8
     */
    @RequestMapping("/queryBanCardUploadLog")
    public Result queryBanCardUploadLog(@RequestParam(value = "deviceid") String deviceid) {
        logger.info("deviceid={}", deviceid);
        return detailsService.queryBanCardUploadLog(deviceid);
    }
}
